package org.example;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Stream_Demo6 {
    public static void main(String[] args) {
        ArrayList<String> manlist = new ArrayList<>();
        Collections.addAll(manlist, "张三,23", "李四,24", "王五,25", "张六财,26", "张七望,27");
        ArrayList<String> womanlist = new ArrayList<>();
        Collections.addAll(womanlist, "张莉,23", "李兰,24", "王芳,25", "张萍,26", "张甜,27");
        Stream<String> stream1 = manlist.stream()
                .filter(s -> s.split(",")[0].length() == 3)
                .limit(2);
        Stream<String> stream2 = womanlist.stream()
                .filter(s -> s.split(",")[0].startsWith("张"))
                .skip(1);
        //合并流
        // Stream.concat(stream1, stream2).forEach(System.out::println);
        //和并流装话为集合
        /*List<Actor> actorList = Stream.concat(stream1, stream2).map(new Function<String, Actor>() {
            @Override
            public Actor apply(String s) {
                String name = s.split(",")[0];
                int age = Integer.parseInt(s.split(",")[1]);
                return new Actor(name, age);
            }
        }).collect(Collectors.toList());
        System.out.println(actorList);*/
        System.out.println("----------------1");
        //lambda表达式
        List<Actor> list = Stream.concat(stream1, stream2)
                .map(s -> new Actor((s.split(",")[0]), Integer.parseInt(s.split(",")[1])))
                .collect(Collectors.toList());
        System.out.println(list);
    }
}
